<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;


Route::prefix('v1')->namespace('Api')
    ->name('api.v1.')
    ->middleware('throttle:' . config('api.rate_limits.sign'))
    ->group(function () {
        //图片验证码
        Route::post('captchas', 'CaptchasController@store')->name('api.captchas.store');
        // 短信验证码
        Route::post('verificationCodes', 'VerificationCodesController@store')->name('api.verificationCodes.store');
        // 用户注册
        Route::post('users', 'UsersController@store')->name('api.users.store');
        //第三方登录
        Route::post('socials/{social_type}/authorizations','AuthorizationsController@socialStore')
            ->where('social_type','wechat')
            ->name('api.socials.authorizations.store');
        //登录
        Route::post('authorizations', 'AuthorizationsController@store')->name('api.authorizations.store');
        //刷新登录token
        Route::put('authorizations/current','AuthorizationsController@update')->name('api.authorizations.update');
        Route::delete('authorizations/current','AuthorizationsController@destroy')->name('api.authorizations.destroy');


        Route::middleware('throttle:' . config('api.rate_limits.access'))
            ->group(function () {
                // 游客可以访问的接口
                // 分类列表
                Route::get('categories', 'CategoriesController@index')
                    ->name('categories.index');
                // 某个用户的详情
                Route::get('users/{user}', 'UsersController@show')
                    ->name('users.show');
                //话题列表,详情
                Route::resource('topics', 'TopicsController')->only(['index','show']);

                // 登录后可以访问的接口
                Route::middleware('auth:api')->group(function() {
                    // 当前登录用户信息
                    Route::get('user', 'UsersController@me')
                        ->name('user.show');
                    //上传图片
                    Route::post('images', 'ImagesController@store')->name('api.images.store');
                    //编辑用户信息
                    Route::patch('user', 'UsersController@update')->name('api.user.update');
                    //话题创建，销毁，编辑
                    Route::resource('topics', 'TopicsController')->only(['store','update','destroy']);
                });

                // 游客可以访问的接口


            });
    });
